<?php
namespace app\common\controller;
use think\Controller;
use think\Db;
use think\Request;

class Comm extends Controller
{
    public function __construct() {
        header("Access-Control-Allow-Origin:*");
        header("Access-Control-Allow-Method:POST,GET");
    }

    public function checkParam($need_arr){
        $c_param = input('param.');
        $this->checkParamObj($c_param,$need_arr);
    }

    public function checkParamObj($c_param,$need_arr){
        foreach ($need_arr as $need_item){
            if(is_array($c_param)){
                if(!isset($c_param[$need_item]) || (!$c_param[$need_item] && $c_param[$need_item] != 0)){
                    json_error_msg("参数" . $need_item . "未传入!");
                }
            }
            if(is_object($c_param)){
                if(!isset($c_param->$need_item) || (!$c_param->$need_item && $c_param->$need_item != 0)){
                    json_error_msg("参数" . $need_item . "未传入!");
                }
            }
        }
    }

    public function trimParam(){
        $c_param = input('param.');
        $arr = [];
        foreach ($c_param as $key=>$val){
            $arr[$key] = is_string($val)?trim($val):$val;
        }
        return $arr;
    }

    public function getParam()
    {
        $role_id = input('opt_role_id','','trim');
        $bus_inquiry_no = input('bus_inquiry_no','','trim');
        $vehicle_frame_no = input('vehicle_frame_no','','trim');
        $vehicle_license_num = input('vehicle_license_num','','trim');
        $brand_name = input('brand_name','','trim');
        $car_model = input('car_model','','trim');
        $bus_to_company_name = input('bus_to_company_name','','trim');
        $bus_from_company_name = input('bus_from_company_name','','trim');
        $repair_company = input('repair_company','','trim');
        $bus_user = input('bus_user','','trim');
        $returned_money_state = input('returned_money_state','','trim');
        $send_goods_state = input('send_goods_state','','trim');
        $invoice_state = input('invoice_state','','trim');

        $bus_user_name = input('bus_user_name','','trim');
        $bus_user_phone = input('bus_user_phone','','trim');
        $repair_company_name = input('repair_company_name','','trim');
        $repair_company_phone = input('repair_company_phone','','trim');
        $logistics_name = input('logistics_name','','trim');
        $supply_comp_name = input('supply_comp_name','','trim');
        $add_user_name = input('add_user_name','','trim');
        $quote_company_name = input('quote_company_name','','trim');

        $param = array();
        if($role_id == 2){
            $param['add_user_id'] = input('opt_user_id');
        }
        if($bus_inquiry_no){
            $param['bus_inquiry_no'] = ['like','%'.$bus_inquiry_no.'%'];
        }
        if($vehicle_frame_no){
            $param['vehicle_frame_no'] = ['like','%'.$vehicle_frame_no.'%'];
        }
        if($vehicle_license_num){
            $param['vehicle_license_num'] = ['like','%'.$vehicle_license_num.'%'];
        }
        if($brand_name){
            $param['brand_name'] = ['like','%'.$brand_name.'%'];
        }
        if($car_model){
            $param['car_model'] = ['like','%'.$car_model.'%'];
        }
        if($bus_from_company_name){
            $param['bus_from_company_name'] = ['like','%'.$bus_from_company_name.'%'];
        }
        if($bus_to_company_name){
            $param['bus_to_company_name'] = ['like','%'.$bus_to_company_name.'%'];
        }
        if($repair_company){
            $param['repair_company_name|repair_company_phone'] = ['like','%'.$repair_company.'%'];
        }
        if($bus_user){
            $param['bus_user_name|bus_user_phone'] = ['like','%'.$bus_user.'%'];
        }
        if($returned_money_state || $returned_money_state !== ''){
            $param['returned_money_state'] = $returned_money_state;
        }
        if($send_goods_state || $send_goods_state !== ''){
            $param['send_goods_state'] = $send_goods_state;
        }
        if($invoice_state || $invoice_state !== ''){
            $param['invoice_state'] = $invoice_state;
        }
        if($bus_user_name){
            $param['bus_user_name'] = ['like','%'.$bus_user_name.'%'];
        }
        if($bus_user_phone){
            $param['bus_user_phone'] = ['like','%'.$bus_user_phone.'%'];
        }
        if($repair_company_name){
            $param['repair_company_name'] = ['like','%'.$repair_company_name.'%'];
        }
        if($repair_company_phone){
            $param['repair_company_phone'] = ['like','%'.$repair_company_phone.'%'];
        }
        if($logistics_name){
            $param['logistics_name'] = ['like','%'.$logistics_name.'%'];
        }
        if($supply_comp_name){
            $param['sure_company_name'] = ['like','%'.$supply_comp_name.'%'];
        }
        if($add_user_name){
            $param['add_user_name'] = ['like','%'.$add_user_name.'%'];
        }
        if($quote_company_name){
            $param['quote_company_name'] = ['like','%'.$quote_company_name.'%'];
        }
        return $param;
    }
}
